package com.gitee.wsl.common.chart.render.foreground.info

import android.graphics.Canvas
import android.graphics.Paint
import com.gitee.wsl.common.chart.model.PlotDot

/**
 * @ClassName Legend
 * @Description 动态图例 基类
 * @author XiongChuanLiang<br/>(xcl_168@aliyun.com)
 *
 */
class Legend : Info() {
     var xPercentage = 0.0f
     var yPercentage = 0.0f


    /**
     * 设置显示位置
     * @param xPercentage    占绘图区的竖向百分比位置
     * @param yPercentage    占绘图区的横向百分比位置
     */
    fun setPosition(xPercentage: Float, yPercentage: Float) {
        this.xPercentage = xPercentage
        this.yPercentage = yPercentage
    }

    /**
     * 增加动态图例
     * @param text    文本
     * @param paint    画笔
     */
    fun addLegend(text: String, paint: Paint) {
        addInfo(text, paint)
    }

    /**
     * 增加动态图例
     * @param dotStyle        图案风格
     * @param text            文本
     * @param paint            画笔
     */
    fun addLegend(dotStyle: PlotDot, text: String, paint: Paint) {
        addInfo(dotStyle, text, paint)
    }

    fun addLegend(items:List<LegendItem>){
        items.forEach {
            addLegend(it.mLstDotStyle,it.text,it.paint)
        }
    }

    fun setPlotWH(width: Float, height: Float) {
        setCenterXY(width * xPercentage, height * yPercentage)
    }

    fun renderInfo(canvas: Canvas) {
        drawInfo(canvas)
    }

}

class LegendItem(val text: String,
                     val paint: Paint,
                     val mLstDotStyle: PlotDot
)